<template>
  <div>
    <el-card class="box-card">
      <!-- 头部 -->
      <div slot="header" class="Sale ">
        <!-- @tab-click="handleClick" -->
        <!-- 展示图表部分 -->
        <el-tabs v-model="activeName">
          <el-tab-pane label="销售额" name="sale" />
          <el-tab-pane label="访问量" name="visit" />
        </el-tabs>
        <!-- 日历部分 -->
        <div class="calendar">
          <span @click="setTody">今日</span>
          <span @click="setWeek">本周</span>
          <span @click="setMonth">本月</span>
          <span @click="setYear">本年</span>
          <el-date-picker
            v-model="data"
            style="width:280px;"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            size="mini"
            value-format="yyyy-MM-dd"
          />
        </div>
      </div>
      <!-- 横线 -->
      <div class="line" />
      <!-- 内容区域 -->
      <div>
        <el-row :gutter="10">
          <el-col :span="18">
            <!-- echarts表格 -->
            <div class="contain">
              <BarCharts :title="title" />
            </div>
          </el-col>
          <el-col :span="6">
            <h3> 门店{{ title }}排名</h3>
            <ul>
              <li>
                <span class="num">1</span>
                <span>肯德基</span>
                <span class="value">323,234</span>
              </li>
              <li>
                <span class="num">2</span>
                <span>肯德基</span>
                <span class="value">323,234</span>
              </li>
              <li>
                <span class="num">3</span>
                <span>肯德基</span>
                <span class="value">323,234</span>
              </li>
              <li>
                <span class="num">4</span>
                <span>肯德基</span>
                <span class="value">323,234</span>
              </li>
              <li>
                <span class="num">5</span>
                <span>肯德基</span>
                <span class="value">323,234</span>
              </li>
              <li>
                <span class="num">6</span>
                <span>肯德基</span>
                <span class="value">323,234</span>
              </li>
              <li>
                <span class="num">7</span>
                <span>肯德基</span>
                <span class="value">323,234</span>
              </li>

            </ul>
          </el-col>
        </el-row>
      </div>
    </el-card>
  </div>
</template>

<script>
import dayjs from 'dayjs'
import BarCharts from './BarCharts/index.vue'
export default {
  name: 'Sale',
  components: {
    BarCharts
  },
  data() {
    return {
      activeName: 'sale',
      // 收集选择日期的信息
      data: ''
    }
  },
  computed: {
    // 标题计算属性
    title() {
      return this.activeName === 'sale' ? '销售额' : '访问量'
    }
  },
  methods: {
    // 本天
    setTody() {
      var data = dayjs().format('YYYY-MM-DD')
      this.data = [data, data]
    },
    // 本周
    setWeek() {
      var start = dayjs().day(1).format('YYYY-MM-DD')
      var end = dayjs().day(7).format('YYYY-MM-DD')
      this.data = [start, end]
    },
    // 本月
    setMonth() {
      var start = dayjs().startOf('month').format('YYYY-MM-DD')
      var end = dayjs().endOf('month').format('YYYY-MM-DD')
      this.data = [start, end]
    },
    // 本年
    setYear() {
      var start = dayjs().startOf('year').format('YYYY-MM-DD')
      var end = dayjs().endOf('year').format('YYYY-MM-DD')
      this.data = [start, end]
    }
  }
}
</script>

<style lang="less" scoped>
.Sale {
  display: flex;
  justify-content: space-between;
}
.calendar span{
  margin: 0 10px;
}
.calendar span:nth-child(4){
  margin: 0 30px 0 0;
}
.contain {
  width: 100%;
  height: 300px;
}
//清除横线
/deep/.el-card__header{
  border-bottom: none;
}
.box-card{
  position: relative;
}
//设置横线
.line {
  position: absolute;
  top: 58px;
  width: 100%;
  height: 1px;
  background-color: #eee;
}
ul {
  list-style: none;
  height: 300px;
  padding: 0
}
ul li {
  display: flex;
  justify-content: space-between;
  height: 40px;
}
ul li:nth-child(-n+3) .num {
  display: inline-block;
  width: 20px;
  height: 20px;
  background-color: black;
  border-radius: 50%;
  color: white;
  text-align: center;
  line-height: 20px;
}
h3 {
  margin: 0;
  padding: 0;
}
</style>
